package com.uchengwang.ui.cm_ui.cycle.http;

import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;

import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.functions.http.entity.MapRequest;
import com.uchengwang.functions.http.listener.HttpCallBack;
import com.uchengwang.functions.http.listener.IHttpManager;
import com.uchengwang.functions.http.listener.OnHttpResultListener;
import com.uchengwang.functions.http.listener.OnHttpResultSingleListener;
import com.uchengwang.functions.http.listener.OnResultListener;
import com.uchengwang.functions.http.manager.HttpManager;
import com.uchengwang.ui.UChengApplication;
import com.uchengwang.ui.cm_ui.cycle.bean.ArticleBean;
import com.uchengwang.ui.cm_ui.cycle.bean.ArticleListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleListNoticeBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleNoticeBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleShareBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleShareListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleSubPeopleSharesBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleSubPeopleSharesListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleThemeBean;
import com.uchengwang.ui.cm_ui.cycle.bean.CycleThemeListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.TalentPeopleBean;
import com.uchengwang.ui.cm_ui.cycle.bean.TalentPeopleListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.VoteDataBean;
import com.uchengwang.ui.cm_ui.cycle.bean.VoteDataListBean;
import com.uchengwang.ui.cm_ui.cycle.bean.VoteItemListBean;
import com.uchengwang.ui.cm_ui.login.bean.UserBean;
import com.uchengwang.ui.cm_ui.release.bean.VoteBean;
import com.uchengwang.ui.cm_ui.ucity.cityBean.UserBeanList;
import com.uchengwang.ui.utils.DatasUtil;
import com.uchengwang.ui.utils.JsonUtils;
import com.uchengwang.ui.utils.LoadingUtils;
import com.uchengwang.ui.utils.UCommonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2018/1/24.
 * 社圈相关的网络请求
 */

public class CycleHttpUtils {
    private static CycleHttpUtils utils;

    private boolean isAllow = true;

    private CycleHttpUtils(){}
    public static CycleHttpUtils getUtils() {
        if (utils ==null){
            utils = new CycleHttpUtils();
        }
        return utils;
    }

    /**
     * 获取我/他人 关注的社圈
     * @param uid 自己或者他人的id
     * @param cycleType 类别,用于区分各个模块(例:体育/兴趣 )
     * */
    public void getFollowCircle(Activity activity, long uid, int page, int perPage, int cycleType, final OnHttpResultListener<CycleBean> listener){
        LoadingUtils.getUtils().loading(activity);
        MapRequest map = new MapRequest();
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);
        if (cycleType >0){
            map.put(BaseConfig.CYCLE_TYPE, cycleType);
        }
        String url = "";
        if (UCommonUtil.getUtil().getId() == uid){
            //获取自己的订阅的圈子
            url = CycleConfig.cycle_Sub_url;
        }else {
            url = CycleConfig.cycle_sub_other_url;//获取别人订阅的圈子
            map.put(BaseConfig.CHECK_UID, uid);
        }

        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, url, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0 , null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                if (status ==0 && !TextUtils.isEmpty(data) && !data.equals("[]")){
                    CycleListBean bean = JsonUtils.getManager().stringToBean(data, CycleListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0 , null);
                }
            }
        });
    }

    /**
     * 订阅某个社圈
     * @param isSub true订阅社圈  false取消订阅
     * */
    public void subOrDeleteCycle(Activity activity, boolean isSub, long cycleId, long uniId, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        MapRequest map = new MapRequest();
        IHttpManager.RequestMethod method = null;
        String url = "";
        if (isSub){
            //订阅
            method = IHttpManager.RequestMethod.POST;
            url = CycleConfig.cycle_Sub_url;
            map.put(BaseConfig.CYCLE_ID, cycleId);
            map.put(BaseConfig.UNI_ID, uniId);
        }else {
            //取消订阅
            method = IHttpManager.RequestMethod.DELETE;
            url = CycleConfig.cycle_Sub_url +"/" + cycleId;
            map.put(BaseConfig.UNI_ID, uniId);
        }
        HttpManager.newInstance(activity).queryCheck(method, url, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 社团关联获取取消社圈
     * @param isSub true 关联 false取消
     * */
    public void clubLinkCycle(Activity activity, boolean isSub, long cycleId, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        MapRequest map = new MapRequest();
        map.put(BaseConfig.CYCLE_ID, cycleId);

        IHttpManager.RequestMethod method = null;
        if (isSub){
            method = IHttpManager.RequestMethod.POST;
        }else {
            method = IHttpManager.RequestMethod.DELETE;
        }

        HttpManager.newInstance(activity).query(method, CycleConfig.CLUB_SUB_CYCLE, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }


    /**
     * 获取我的/他人发布内容
     * @param uid 用户id
     * @param cycleId 圈子的id
     * @param shareType 类别,用于区分各个模块 (例:享说/活动/投票等类)
     * */
    public void getShare(Activity activity, long uid, int cycleId, int page, int perPage, int shareType, final OnHttpResultListener<CycleShareBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);
        if (shareType >0){
            map.put(BaseConfig.SHARE_TYPE, shareType);
        }
        String url = "";
        if (uid ==UCommonUtil.getUtil().getId()){
            //自己的发布信息
            url = CycleConfig.cycle_share_my_url;
        }else {
            //别人的发布信息
            url = CycleConfig.cycle_share_other_url;
            map.put(BaseConfig.CHECK_UID, uid);
            if (cycleId >0){
                map.put(BaseConfig.CYCLE_ID, cycleId);
            }
        }
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, url, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0 , null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data) && !data.equals("[]")){
                    CycleShareListBean bean = JsonUtils.getManager().stringToBean(data, CycleShareListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0 , null);
                }
            }
        });
    }

    /***
     * 发布社圈信息
     * */
    public void releaseCycleInfo(Activity activity, MapRequest map, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        if (!isAllow){
            UCommonUtil.getUtil().showToast(activity, "正在提交中...");
            return;
        }
        isAllow = false;
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, CycleConfig.CYCLE_SHARE, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                isAllow = true;
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                isAllow = true;
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 创建社圈
     * */
    public void createCycle(Activity activity, MapRequest map, final OnResultListener listener){
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/cycle/new", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                listener.onResult(status, msg, 0, null);
            }
        });

    }


    /**
     * 创建社圈时 获取社圈所属的主题
     * */
    public void getCycleTheme(Activity activity, int cycleType, int page, final OnHttpResultListener<CycleThemeBean> listener){
        MapRequest map =new MapRequest();
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, 20);
        if (cycleType >0){
            map.put(BaseConfig.CYCLE_TYPE, cycleType);
        }
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/cycle/item", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    CycleThemeListBean bean = JsonUtils.getManager().stringToBean(data, CycleThemeListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     *申请加入社圈
     * */
    public void joinCycle(Activity activity , long cycleId, String realName, String desc, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        MapRequest map = new MapRequest();
        map.put(BaseConfig.CYCLE_ID, cycleId);
        map.put(BaseConfig.REAL_NAME, realName);
        if (!TextUtils.isEmpty(desc)){
            map.put(BaseConfig.DESCRIPTION, desc);
        }

        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/cycle/join", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });

    }



    /**
     * 消息互动的接口
     * @param isRead 是否已读
     * @param updateRead 是否标记所有消息为已读
     * */
    public void getCycleNotice(Activity activity, int page, int perPage, Boolean updateRead, Boolean isRead, final OnHttpResultListener<CycleNoticeBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);
        if (updateRead != null){
            map.put(BaseConfig.UPDATE_READ, updateRead);
        }
        if (isRead != null){
            map.put(BaseConfig.IS_READ, isRead);
        }
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, CycleConfig.CYCLE_NOTICE, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    CycleListNoticeBean bean = JsonUtils.getManager().stringToBean(data, CycleListNoticeBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     * 获取社圈
     * */
    public void getCycles(Activity activity, long uniId, int cycleType, int page, int perPage, final OnHttpResultListener<CycleBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.PERPAGE, perPage);
        map.put(BaseConfig.PAGE, page);
        if (uniId >0){
            map.put(BaseConfig.UNI_ID, uniId);
        }
        if (cycleType >0){
            map.put(BaseConfig.CYCLE_TYPE, cycleType);
        }
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, CycleConfig.CYCLE, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    CycleListBean bean = JsonUtils.getManager().stringToBean(data, CycleListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     * 获取一个社圈的粉丝
     * */
    public void getCycleFans(Activity activity, long cycleId, long uniId, int page, int perPage, final OnHttpResultListener<UserBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.CYCLE_ID, cycleId);
        if (uniId >0){
            map.put(BaseConfig.UNI_ID, uniId);
        }
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, CycleConfig.CYCLE_SUB_USER, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    UserBeanList beanList = JsonUtils.getManager().stringToBean(data, UserBeanList.class);
                    listener.onResult(status, msg, beanList.getTotalPage(), beanList.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     * 获取一个人创建和加入的社圈
     * */
    public void getCreateAndJoinCycles(final Activity activity, final long checkUid, final int cycleType, final OnHttpResultListener<CycleBean> listener){
        final List<CycleBean> cycleBeanList = new ArrayList<>();
        getCreateCycles(activity, checkUid, cycleType, 1, 999, null, new OnHttpResultListener<CycleBean>() {
            @Override
            public void onResult(int status, String msg, int total, List<CycleBean> list) {
                if (list != null){
                    cycleBeanList.addAll(list);
                }
                //在获取自己加入的社圈
                getJoinCycles(activity, checkUid, cycleType, 1, 999, new OnHttpResultListener<CycleBean>() {
                    @Override
                    public void onResult(int status, String msg, int total, List<CycleBean> list) {
                        if (list != null){
                            cycleBeanList.addAll(list);
                        }
                        listener.onResult(status, msg, 0, cycleBeanList);
                    }
                });

            }
        });
    }



    /**
     * 获取某个人创建的社圈
     * */
    public void getCreateCycles(Activity activity, long checkUid, int cycleType, int page, int perpage, Boolean updateIsRead, final OnHttpResultListener<CycleBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.CHECK_UID, checkUid);
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perpage);
        if (cycleType >0){
            map.put(BaseConfig.CYCLE_TYPE, cycleType);
        }
        if (updateIsRead != null){
            map.put(BaseConfig.UPDATE_IS_READ, updateIsRead);
        }
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/cycle/create", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                Log.d("jjf", "返回状态="+status+"==msg=="+msg);
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                Log.d("jjf", "返回状态="+status+"==msg=="+msg);
                if (status ==0 && !TextUtils.isEmpty(data)){
                    CycleListBean bean = JsonUtils.getManager().stringToBean(data, CycleListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }


    /**
     * 获取推荐的圈子
     * */
    public void getRecommendCycles(Activity activity, final OnHttpResultListener<CycleBean> listener){
        MapRequest map = new MapRequest();
        if (UChengApplication.myUniId >0){
            map.put(BaseConfig.UNI_ID, UChengApplication.myUniId);
        }

        HttpManager.newInstance(activity).queryCheck(IHttpManager.RequestMethod.GET, "/cycle/recommend", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                Log.d("srm", "status=="+status+"==msg=="+msg);
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                Log.d("srm", "status=="+status+"==msg=="+msg+"=data="+data);
                if (status ==0 && !TextUtils.isEmpty(data)){
                    List<CycleBean> list = JsonUtils.getManager().parseList(data, CycleBean.class);
                    listener.onResult(status, msg, 0, list);
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });


    }

    /**
     * 获取某个人加入的社圈
     * */
    public void getJoinCycles(Activity activity, long checkUid, int cycleType, int page, int perpage, final OnHttpResultListener<CycleBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.CHECK_UID, checkUid);
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perpage);
        if (cycleType >0){
            map.put(BaseConfig.CYCLE_TYPE, cycleType);
        }
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/cycle/joincycle", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    CycleListBean bean = JsonUtils.getManager().stringToBean(data, CycleListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }


    /**
     * 获取某个社圈的新申请
     * */
    public void getCycleNewApply(Activity activity, long cycleId, boolean updateIsRead, final OnResultListener listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.CYCLE_ID, cycleId);
        map.put(BaseConfig.UPDATE_IS_READ, updateIsRead);
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/cycle/join/new", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                Log.d("jjf", "status =="+status+"=msg="+msg);
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                Log.d("jjf", "status =="+status+"=msg="+msg);
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 创建社圈时 检查邀请码的有效性
     * */
    public void checkInviteCode(Activity activity, String inviteCode, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        MapRequest map = new MapRequest();
        map.put(BaseConfig.INVITE_CODE, inviteCode);
        HttpManager.newInstance(activity).queryCheck(IHttpManager.RequestMethod.GET, "/cycle/checkinvitecode", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }



    /**
     * 发布社圈活动信息
     * */
    public void releaseAct(Activity activity, final MapRequest map, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/act", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);

            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 发布一个投票  包括被投票人的信息
     * */
    public void releaseVote(Activity activity, MapRequest map, final OnHttpResultSingleListener<VoteDataBean> listener){
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/act/vote/new", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    VoteDataBean bean = JsonUtils.getManager().stringToBean(data, VoteDataBean.class);
                    listener.onResult(status, msg, bean);
                }else {
                    listener.onResult(status, msg, null);
                }
            }
        });
    }

    /**
     * 发布一个投票  发布的是投票人的信息
     * */
    public void releasePersonVote(Activity activity, MapRequest map, final OnResultListener listener){
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/act/vote/item", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 获取投票信息
     * */
    public void getVoteItems(Activity activity, MapRequest map, final OnHttpResultListener<VoteBean> listener){
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/act/vote/item", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    VoteItemListBean bean = JsonUtils.getManager().stringToBean(data, VoteItemListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     * 发布一个会场
     * */
    public void releaseEvent(Activity activity, MapRequest map, final OnResultListener listener){
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/event", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 获取某个人发布的投票信息
     * */
    public void getVotes(Activity activity, MapRequest map, final OnHttpResultListener<VoteDataBean> listener){
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/act/vote/base", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status == 0 && !TextUtils.isEmpty(data)){
                    VoteDataListBean bean = JsonUtils.getManager().stringToBean(data, VoteDataListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }


    /**
     * 查询关注圈是否有新动态
     * @param updateRead 如果为true,会将所有数据设置为已读
     * */
    public void checkFollowNew(Activity activity, boolean updateRead, final OnResultListener listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.UPDATE_READ, updateRead);
        HttpManager.newInstance(activity).queryCheck(IHttpManager.RequestMethod.GET, "/cycle/sub/check", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data)){
                    boolean newSub = JsonUtils.getManager().getJSONObject(data).getBooleanValue("newSub");
                    if (newSub){
                        listener.onResult(status, msg, 0, "新消息");
                    }else {
                        listener.onResult(status, msg, 0, "");
                    }
                }else {
                    listener.onResult(status, msg, 0, "");
                }
            }
        });
    }

    /**
     * 屏蔽信息
     * @param shareId 如果为true,会将所有数据设置为已读
     * */
    public void blockShare(Activity activity, long shareId, final OnResultListener listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.SHARE_ID, shareId);
        HttpManager.newInstance(activity).queryCheck(IHttpManager.RequestMethod.POST, "/cycle/share/ban", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                listener.onResult(status, msg, 0, "");
            }
        });
    }

    /**
     * 删除自己发布的信息
     * referType  1=会场(event) 2=享说(/cycle/share) 3=投票(vote) 4=聊天(chat) 5=活动(act)  7文章
     * @param id 信息id
     * @param referType 信息类型
     * */
    public void deleteCycleInfo(Activity activity, long id, int referType, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        IHttpManager.RequestMethod method = null;
        String url = "";
        MapRequest map = new MapRequest();
        switch (referType){
            case 1://会场
                url = "/event";
                method = IHttpManager.RequestMethod.PUT;
                map.put(BaseConfig.EVENT_ID, id);
                map.put(BaseConfig.IS_ACTIVI, false);

                break;
            case 2://享说/视频
                method = IHttpManager.RequestMethod.DELETE;
                url = CycleConfig.CYCLE_SHARE;
                map.put(BaseConfig.SHARE_ID, id);
                break;
            case 3://投票
                method = IHttpManager.RequestMethod.DELETE;
                url = "/act/vote";
                map.put(BaseConfig.VOTE_ID, id);
                break;
            case 5://活动
                method = IHttpManager.RequestMethod.PUT;
                url = "/act";
                map.put(BaseConfig.ACT_ID, id);
                map.put(BaseConfig.IS_ACTIVI, false);
                break;
            case BaseConfig.SHARE_ARTICLE:
                method = IHttpManager.RequestMethod.DELETE;
                url = "/article";
                map.put(BaseConfig.ARTICLE_ID, id);
                break;
        }

        HttpManager.newInstance(activity).query(method, url, map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 获取订阅人所发布的信息
     * @param isNeedAgainCmt 是否需要重新编排评论回复信息  true需要
     * **/
    public void getSubPeopleShares(Activity activity, int page, int perPage, final boolean isNeedAgainCmt, final OnHttpResultListener<CycleSubPeopleSharesBean> listener){
        MapRequest map = new MapRequest();
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/cycle/sub/share", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data) && !data.equals("[]")){
                    CycleSubPeopleSharesListBean bean = JsonUtils.getManager().stringToBean(data, CycleSubPeopleSharesListBean.class);
                    List<CycleSubPeopleSharesBean> sharesBeans = bean.getData();
                    if (isNeedAgainCmt){
                        sharesBeans = DatasUtil.createCommentItemList(sharesBeans);
                    }

                    listener.onResult(status, msg, bean.getTotalPage(), sharesBeans);
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     * 获取达人
     * */
    public void getTalentPeoples(Activity activity, long cycleItemId, int page, int perPage, Boolean isHot, Boolean isRecom,
                                 long uniId, String orderBy, String order,final OnHttpResultListener<TalentPeopleBean> listener){
        MapRequest map = new MapRequest();
        if (cycleItemId >0 ){
            map.put(BaseConfig.CYCLE_ITEM_ID, cycleItemId);
        }
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);
        if (isHot != null ){
            map.put(BaseConfig.IS_HOT, isHot);
        }

        if (isRecom != null ){
            map.put(BaseConfig.IS_RECOMMEND, isRecom);
        }

        if (uniId >0 ){
            map.put(BaseConfig.UNI_ID, uniId);
        }

        if (!TextUtils.isEmpty(order) && !TextUtils.isEmpty(orderBy)){
            map.put(BaseConfig.ORDERBY, orderBy);
            map.put(BaseConfig.ORDER, order);
        }

        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/talent", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data) && !data.equals("[]")){
                    TalentPeopleListBean bean = JsonUtils.getManager().stringToBean(data, TalentPeopleListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }


    /**
     * 获取达人圈的信息
     * @param type 1最热  2最新 3本校
     * */
    public void getTalentInfos(Activity activity, long cycleItemId, int page, int perPage, int type, final OnHttpResultListener<ArticleBean> listener){
        MapRequest map = new MapRequest();
        if (cycleItemId >0 ){
            map.put(BaseConfig.CYCLE_ITEM_ID, cycleItemId);
        }
        map.put(BaseConfig.PAGE, page);
        map.put(BaseConfig.PERPAGE, perPage);

        switch (type){
            case 1://最热
                map.put(BaseConfig.ORDERBY, "total_score");
                map.put(BaseConfig.ORDER, "desc");
                break;
            case 2://最新
                map.put(BaseConfig.ORDERBY, "id");
                map.put(BaseConfig.ORDER, "desc");
                break;
            case 3://本校
                map.put(BaseConfig.UNI_ID, UChengApplication.myUniId);
                break;
        }


        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.GET, "/article", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                if (status ==0 && !TextUtils.isEmpty(data) && !data.equals("[]")){
                    ArticleListBean bean = JsonUtils.getManager().stringToBean(data, ArticleListBean.class);
                    listener.onResult(status, msg, bean.getTotalPage(), bean.getData());
                }else {
                    listener.onResult(status, msg, 0, null);
                }
            }
        });
    }

    /**
     * 认证达人
     * */
    public void authTalent(Activity activity, MapRequest map, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/talent/auth", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 给文章打分
     * @param activity
     * @param articleUid 文章作者id
     * @param score */
    public void articleScore(Activity activity, long articleId, long articleUid, int score, final OnResultListener listener){
        LoadingUtils.getUtils().loading(activity);
        MapRequest map = new MapRequest();
        map.put(BaseConfig.ARTICLE_ID, articleId);
        map.put(BaseConfig.ARTICLE_UID, articleUid);
        map.put(BaseConfig.SCORE, score);

        HttpManager.newInstance(activity).query(IHttpManager.RequestMethod.POST, "/article/score", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                LoadingUtils.getUtils().hide();
                listener.onResult(status, msg, 0, null);
            }
        });
    }

    /**
     * 社圈信息点赞 或者取消点赞
     * @param isLike 当前已点赞者取消  没点赞者点赞
     * */
    public void addLikeOrDelete(Activity activity, boolean isLike, long shareId, final OnResultListener listener){
        IHttpManager.RequestMethod method = null;
        if (isLike){
            //取消点赞
            method = IHttpManager.RequestMethod.DELETE;
        }else{
            //点赞
            method = IHttpManager.RequestMethod.POST;
        }

        MapRequest map = new MapRequest();
        map.put(BaseConfig.SHARE_ID, shareId);
        HttpManager.newInstance(activity).query(method, "/cycle/share/like", map, new HttpCallBack() {
            @Override
            public void onError(int status, String msg) {
                listener.onResult(status, msg, 0, null);
            }

            @Override
            public void onResp(int status, String msg, String data) {
                listener.onResult(status, msg, 0, null);
            }
        });
    }

}
